// pages/pay/pay.js
const app = getApp()
var datas;

Page({

  /**
   * 页面的初始数据
   */
  data: {
      items:"",
      ordernum:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var _this = this;
      _this.setData({
        ordernum:options.ordernum
      })
  },
  //上传图片
  Uploadimg: function (e) {
    var that = this;
    wx.chooseImage({
      count:9,  //最多可以选择的图片总数  
      sizeType: ['original', 'compressed'],// 可以指定是原图还是压缩图，默认二者都有 
      success: function (res) {
        console.log(res.tempFilePaths);
        var imgpath = Array();
        wx.showLoading({
          title: '',
          icon: 'none'
        })
        that.imgupload(res.tempFilePaths, 0);

        setTimeout(function () {
          wx.hideLoading();
        },500);

      }
    })
  },
  imgupload: function (tempFilePaths, i) {
    if (i == 0) {
      datas = [];
    }
    if (i < tempFilePaths.length) {

      var that = this;
      var tmppath = tempFilePaths[i];
      wx.uploadFile({
        url: 'https://fastadmin.ranmengwork.cn/api/index/uploadimg.html',
        filePath: tmppath,
        name: 'images',
        formData: {
        },
        success: function (res) {
          console.log(res);
          var data = JSON.parse(res.data);
          if (data.code == 200) {
            var imgpath=datas
            imgpath.push(data.path);
            datas = imgpath;
            that.setData({
              items: datas
            })
          }
          i++;
          that.imgupload(tempFilePaths, i);
        }
      });
    }
  },
  //保存交易图片
  backtap:function(e){
    var formid = e.detail.formId;
    var _this = this
    wx.request({
      url: app.globalData.apiurl + "api/index/setformids",
      method: "GET",
      data: {
        uid: app.globalData.userInfo.user_id,
        formid: formid
      },
      header: {
        'content': "json"
      },
      success(e) {

      }
    });
    if (_this.data.items==""){
      wx.showToast({
        title: '请上传照片',
        icon: 'none'
      })
      return false;
    }else{
      wx.request({
        url: app.globalData.apiurl + 'api/index/payimg',
        method: "GET",
        data: {
          ordernum: _this.data.ordernum,
          data: datas
        },
        success: function () {
          wx.navigateTo({
            url: '/pages/order/order',
          })
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})